﻿
using System;
using System.Data;
using System.Data.Common;
using System.Collections.Generic;
using Microsoft.JCI.Common.Utility;
using System.Text;
namespace Microsoft.JCI.Dal
{
    /// <summary>
    /// DAL layer class dbo.Jci_Sys_Company.
    /// </summary>
    public partial class SysCompanyDal : DalBase
    {
        public DataTable QueryCompanyEntity(List<SqlDbParameter> Conditions)
        {
            StringBuilder sqlStr = new StringBuilder();

            sqlStr.Append(@"
select * from Jci_Sys_Company");

            string sqlFormat = sqlStr.Append(" where 1=1 {1}").ToString();
            string sql = SqlDbParameter.BuildSqlString(sqlFormat, Conditions);
            DbCommand dbCommand = this._db.GetSqlStringCommand(sql);
            foreach (SqlDbParameter parameter in Conditions)
            {
                parameter.SetDbCommond(dbCommand);
            }
            DataSet ds = this._db.ExecuteDataSet(dbCommand);
            return ds.Tables[0];
        }

        public DataTable QueryVendorEntity(List<SqlDbParameter> Conditions)
        {
            StringBuilder sqlStr = new StringBuilder();

            sqlStr.Append(@"
select * from (
select a.*,b.Name AS BranchName,b.CompanyCode as BranchCode from Jci_Sys_Company a
left join Jci_Sys_Company b on a.ParentCompanyCode = a.CompanyCode) c
");

            string sqlFormat = sqlStr.Append(" where 1=1 {1}").ToString();
            string sql = SqlDbParameter.BuildSqlString(sqlFormat, Conditions);
            DbCommand dbCommand = this._db.GetSqlStringCommand(sql);
            foreach (SqlDbParameter parameter in Conditions)
            {
                parameter.SetDbCommond(dbCommand);
            }
            DataSet ds = this._db.ExecuteDataSet(dbCommand);
            return ds.Tables[0];
        }

    }
}
